package com.wct.springcloud.service;

import com.wct.springcloud.model.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author WEI (Email:changtan20000@163.com)
 * @description
 * @date: 2019/12/19 14:45
 */
// 不要忘记添加注解
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory<DeptClientService> {
    @Override
    public DeptClientService create(Throwable cause) {
        return new DeptClientService() {
            @Override
            public boolean add(Dept dept) {
                return false;
            }

            @Override
            public Dept get(Integer deptno) {
                Dept dept = new Dept();
                dept.setDeptno(deptno);
                dept.setDname("该deptno: " + deptno + " 没有对应的信息，Consumer客户端提供的降级信息，此刻服务端provider已经关闭！");
                dept.setDbSource("provider is down！");
                return dept;
            }

            @Override
            public List<Dept> list() {
                List<Dept> list = new ArrayList<>();
                Dept dept = new Dept();
                dept.setDname("没有对应的信息，null--@HystrixCommand");
                dept.setDbSource("no data in MYSQL database");
                list.add(dept);
                return list;
            }

            @Override
            public int update(Dept record) {
                return 0;
            }

            @Override
            public int delete(Integer deptno) {
                return 0;
            }
        };
    }
}
